package com.sc.controller.ahao;

import com.sc.domain.PayMeter;
import com.sc.dto.PayMeterPageDto;
import com.sc.result.PageResult;
import com.sc.result.Result;
import com.sc.service.PayMeterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/payMeter")
@Api(tags = "仪表接口")
@Slf4j
public class PayMeterController {

    @Autowired
    PayMeterService payMeterService;

    @ApiOperation("仪表添加")
    @PostMapping("/add")
    public Result save(@RequestBody PayMeter payMeter) {
        return Result.success("添加成功", payMeterService.save(payMeter));
    }

    @ApiOperation("仪表删除")
    @DeleteMapping("/deleteById")
    public Result deleteById(Long id) {
        return Result.success("删除成功", payMeterService.deleteById(id));
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Long> ids) {
        return Result.success("删除成功", payMeterService.deleteByIds(ids));
    }

    @ApiOperation("仪表修改")
    @PutMapping("/update")
    public Result update(@RequestBody PayMeter payMeter) {
        return Result.success("修改成功", payMeterService.update(payMeter));
    }

    @ApiOperation("仪表查询")
    @GetMapping("/getById")
    public Result<PayMeter> get(Integer id) {
        return Result.success(payMeterService.get(id));
    }

    @ApiOperation("仪表分页查询")
    @PostMapping("/page")
    public Result<PageResult<PayMeter>> page(@RequestBody PayMeterPageDto payMeterPageDto) {
        return Result.success(payMeterService.page(payMeterPageDto));
    }
}
